1. Field of the Invention
This invention relates to the Java Virtual Machine, and more particularly to methods for executing native code in a distributed Java Virtual Machine supporting the Java Native Interface (JNI).
2. Background of the Invention
Implementations of the Java Virtual Machine (JVM) support the Java Native Interface (JNI) as a mechanism to enable Java bytecode to call methods written in native code (e.g., C and C++) and vice versa. Traditionally, both the Java bytecode and the native code are executed in the same process and by the same thread as execution transitions between the two.
It is possible, however, to construct a JVM to execute native code in one or more remote execution containers, which may be executed within separate threads on the same or different machine from where the Java bytecode is executed. In such environments, the native code may not be aware that it is executing separately from the JVM. Separating the Java bytecode and native code in this manner may help to prevent misbehaved native code from destabilizing the JVM. It may also enable the native code to run in a different environment (e.g., security context, bit width, etc.) than the JVM.
Function calls from a JNI process of a remote execution container to a JVM typically have relatively high latency, particularly for operations in which one or both of input and output data is an array. In particular, function calls from the JNI to the JVM typically require at least three round trip communications: a first call to provide an input array to the JVM, a second call to invoke a function operating on the array, and a third call to request an array modified or created as a result of the function.
In view of the foregoing, what are needed are methods to reduce the latency of function calls from a JNI process to a remote JVM.